package com.kuang.service;

import com.kuang.mapper.DepartmentMapper;
import com.kuang.mapper.EmployeeMapper;
import com.kuang.pojo.SystemDept;
import com.kuang.pojo.SystemEmployee;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService{

    @Resource
    private EmployeeMapper employeeMapper;
    @Resource
    private DepartmentMapper departmentMapper;

    // 获取所有员工信息
    public List<SystemEmployee> getEmployees(){
        return employeeMapper.getEmployees();
    }

    // 新增一个员工
    public int save(SystemEmployee employee){
        String dept_code = employee.getDept_code();
        SystemDept systemDept = departmentMapper.getDepartment(dept_code);
        employee.setDept_name(systemDept.getDept_name());
        return employeeMapper.save(employee);
    }

    // 通过id获得员工信息
    public SystemEmployee get(String emp_code){
        return employeeMapper.get(emp_code);
    }

    public SystemEmployee getEmployeeByCode(String emp_code) {
        return employeeMapper.getEmployeeByCode(emp_code);
    }

    // 通过id删除员工
    public int delete(String id){
        return employeeMapper.delete(id);
    }

    //更新员工
    public int update(SystemEmployee employee){
        String dept_code = employee.getDept_code();
        SystemDept systemDept = departmentMapper.getDepartment(dept_code);
        employee.setDept_name(systemDept.getDept_name());
        return employeeMapper.update(employee);
    }

}
